package exception;

import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 异常处理机制再IO操作中的运用
 */
public class FinallyDemo2 {
    public static void main(String[] args) {
        System.out.println("开始...");
        FileOutputStream fos1 = null;
        try{
            fos1 = new FileOutputStream("fos_b.dat");
            fos1.write(1);
        }catch(IOException e){
            System.out.println("错误");
        }finally{
            try {
                if (fos1==null) {
                    fos1.close();
                }
            } catch (IOException e) {
                System.out.println("执行");;
            }
        }

        System.out.println("结束...");



        /*
        System.out.println("开始了...");
        FileOutputStream fos = null;
        try{
            fos = new FileOutputStream("fos.dat");
            fos.write(1);
        }catch (IOException e){
            System.out.println("出现IO异常并解决了");
        }finally {
            try {
                if (fos==null) {
                    fos.close();
                }
            } catch (Exception e) {
                System.out.println("关闭流时出现异常并解决了");
            }
        }
        System.out.println("结束了...");

         */
    }
}
